package com.esm.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

/**
 * 获取当前时间的年月
 * @author 康少
 *
 * 2017年1月12日
 */
public class GetCurrentYearAndTimeController_zxk extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		Date date = new Date();
		int currentyear = date.getYear()+1900;
		int currentmonth = date.getMonth()+1;
		JSONObject jo = new JSONObject();
		jo.put("currentyear", currentyear);
		jo.put("currentmonth", currentmonth);
		jo.put("lastyear", currentyear-1);
		jo.put("lasttwoyear", currentyear-2);
		PrintWriter pw = resp.getWriter();
		pw.write(jo.toString());
		pw.flush();
		pw.close();
	}
}
